package com.tian.service.impl;

import com.tian.convert.ChargeStationConvertUtil;
import com.tian.dto.ChargeStationListReqDto;
import com.tian.dto.ChargeStationListRespDto;
import com.tian.entity.ChargeStation;
import com.tian.mapper.ChargeStationMapper;
import com.tian.service.ChargeStationService;
import com.tian.util.CommonResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * @date 2023年05月12日 11:29
 * 博客地址：<a href="http://woaijava.cc/">博客地址</a>
 * <p>
 * 充电桩
 */
@Service
public class ChargeStationServiceImpl implements ChargeStationService {
    @Resource
    private ChargeStationMapper chargeStationMapper;

    @Override
    public CommonResult<ChargeStationListRespDto> page(ChargeStationListReqDto chargeStationListReqDto) {
        int count = chargeStationMapper.count(chargeStationListReqDto);
        if (count == 0) {
            return CommonResult.success(new ChargeStationListRespDto());
        }
        List<ChargeStation> chargeStationList = chargeStationMapper.list(chargeStationListReqDto);

        ChargeStationListRespDto chargeStationListRespDto = new ChargeStationListRespDto();

        chargeStationListRespDto.setStart(chargeStationListReqDto.getStart() + chargeStationList.size());
        chargeStationListRespDto.setPageSize(chargeStationListReqDto.getPageSize());

        chargeStationListRespDto.setList(ChargeStationConvertUtil.convert(chargeStationList));
        return CommonResult.success(chargeStationListRespDto);
    }
}
